package com.ydj.app.entity;

import com.google.gson.reflect.TypeToken;
import com.ydj.app.enumerate.ForecastQuestionCateEnum;
import com.ydj.app.protocol.dto.ForecastQaItemDto;
import com.ydj.framework.mysql.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import javax.persistence.*;
import java.util.List;

@Getter
@Setter
@Accessors(chain = true)
@Entity
@Table(name = "forecast_question",
        indexes = {@Index(name = "idx_cate", columnList = "cate")},
        uniqueConstraints = {@UniqueConstraint(name = "uni_cate", columnNames = {"cate"})}
)
@org.hibernate.annotations.Table(appliesTo = "forecast_question", comment = "RWA预测的问题")
public class ForecastQuestion extends BaseEntity {
    @Column(columnDefinition = "longtext comment '问题队列的JSON'", nullable = false)
    private String questionJson;

    @Column(columnDefinition = "tinyint comment '预测类别'", nullable = false)
    private ForecastQuestionCateEnum cate;

    public List<ForecastQaItemDto> getQuestionList() {
        return gson.fromJson(questionJson, new TypeToken<List<ForecastQaItemDto>>() {
        }.getType());
    }

    public ForecastQuestion setQuestionList(List<ForecastQaItemDto> questionList) {
        questionJson = gson.toJson(questionList);
        return this;
    }
}